<template>
	<view class="container">
		<view class="product bg-fff">
			<view class="product-item flex" v-for="(it,idx) in dataInfo.product" :key="idx">
				<image class="product-item-image" :src="it.image.file_path"></image>
				<view class="product-item-con">
					<view class="product-item-name u-line-1">{{it.product_name}}</view>
					<view class="product-item-suk">{{it.product_attr}}</view>
					<view class="flex-space-between">
						<view class="product-item-price">￥{{it.product_price}}</view>
						<view class="product-item-num">x{{it.total_num}}</view>
					</view>
				</view>
			</view>
		</view>
		
		<view class="type bg-fff">
			<view class="type-title">服务类型</view>
			
			<view class="type-list flex-align-center">
				<view class="type-item" :class="{'type-item-select': form.refund_type == item.value}" v-for="(item,index) in typeList" :key="index" @click="form.refund_type = item.value">{{item.label}}</view>
			</view>
		</view>
		
		<view class="content bg-fff">
			<view class="content-title">申请原因</view>
			<view class="flex">
				<textarea v-model="form.content" placeholder="请详细填写申请原因，注意保持商品完好，建议您先与卖家沟通"></textarea>
			</view>
		</view>
		
		<view class="total bg-fff flex-space-between">
			<view class="total-title">退款金额</view>
			<view class="total-price">￥{{dataInfo.pay_price || 0}}</view>
		</view>
		
		<view class="image bg-fff">
			<view class="image-title">上传凭证<text>（最多6张）</text></view>
			<u-upload 
				width="150rpx" 
				height="150rpx" 
				:header="{'Cookie': 'XDEBUG_TRIGGER=;'}"
				:form-data="{
					token: token,
					app_id: app_id,
				}"
				:max-count="6"
				name="iFile"
				:action="$setting.baseUrl()+'/file.upload/image'" 
				@on-success="handleUploadSuccess()"
				@on-remove="handleUploadRemove()"></u-upload>
		</view>
		
		<b-u-button-theme width="630rpx" height="90rpx" size="30rpx" @click="send">确认提交</b-u-button-theme>
		
		<safe-area-inset-bottom></safe-area-inset-bottom>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token: uni.getStorageSync('token'),
				app_id: uni.$setting.appId,
				dataInfo: {},
				typeList: [
					{
						label: "退货/退款",
						value: 10,
					},
					// {
					// 	label: "换货",
					// 	value: 20,
					// },
					{
						label: "仅退款",
						value: 30,
					},
				],
				form: {
					refund_type: 10,
					content: "",
					images: [],
					order_id: '',
				},
			}
		},
		onLoad(options) {
			this.form.order_id = options.order_id;
			this.getHttp();
		},
		methods: {
			send() {
				if(uni.$u.test.isEmpty(this.form.content)) {
					uni.showToast({
						title: "请输入申请原因",
						icon: "none"
					})
					return;
				}
				
				
				let params = JSON.parse(JSON.stringify(this.form));
				params.images = JSON.stringify(params.images);
				uni.$u.api.postRefund(params).then(res => {
					uni.showModal({
						title: '提示',
						content: '提交成功',
						showCancel: false,
						success: function (res) {
							if (res.confirm) {
								uni.navigateBack();
								// console.log('用户点击确定');
							} else if (res.cancel) {
								// console.log('用户点击取消');
							}
						}
					});
				})
			},
			handleUploadSuccess(e) {
				this.form.images.push(e.data);
			},
			handleUploadRemove(index) {
				this.form.images.splice(index, 1);
			},
			getRefund() {
				uni.$u.api.getRefund({
					order_id: this.form.order_id,
					platform: 'wx',
				}).then(res => {
					this.dataInfo = res.order;
				})
			},
			getHttp() {
				this.getRefund();
			},
		},
	}
</script>

<style lang="scss" scoped>
	.container {
		
		.product {
			padding: 24rpx 30rpx;
			
			.product-item {
				
				.product-item-image {
					width: 128rpx;
					height: 128rpx;
				}
			
				.product-item-con {
					margin-left: 16rpx;
					flex: 1;
			
					.product-item-name {
						width: 460rpx;
						font-size: 28rpx;
						color: #111111;
					}
			
					.product-item-suk {
						font-size: 24rpx;
						color: #999999;
						margin-bottom: 10rpx;
					}
			
					.product-item-num {
						font-size: 24rpx;
						color: #999999;
					}
			
					.product-item-price {
						font-size: 28rpx;
						color: $uni-color-theme;
					}
				}
			}
			
			.product-item +.product-item {
				margin-top: 20rpx;
			}
		}
		
		.type {
			padding: 30rpx;
			margin: 24rpx 30rpx 0;
			
			.type-title {
				font-size: 32rpx;
				color: #333333;
				font-weight: bold;
			}
			
			.type-list {
				margin-top: 40rpx;
				
				.type-item {
					font-size: 28rpx;
					color: #333333;
					padding: 20rpx;
					border-radius: 16rpx;
					background: #E1E1E1;
					margin-right: 32rpx;
				}
				
				.type-item-select {
					background: #BB0024;
					color: #FFFFFF;
				}
			}
		}
		
		.content {
			padding: 22rpx 30rpx;
			margin: 24rpx 30rpx 0;
			border-radius: 20rpx;
			
			.content-title {
				font-size: 32rpx;
				color: #333333;
				font-weight: bold;
			}
			
			textarea {
				margin-top: 20rpx;
				padding: 30rpx;
				height: 220rpx;
				border-radius: 20rpx;
				background: #F6F6F6;
			}
		}
		
		.total {
			padding: 24rpx 30rpx;
			margin: 24rpx 30rpx 0;
			border-radius: 20rpx;
			
			.total-title {
				font-size: 32rpx;
				color: #333333;
				font-weight: bold;
			}
			
			.total-price {
				font-size: 32rpx;
				color: #E80D0D;
			}
		}
		
		.image {
			padding: 24rpx 30rpx;
			margin: 24rpx 30rpx 52rpx;
			border-radius: 20rpx;
			
			.image-title {
				font-size: 32rpx;
				color: #333333;
				font-weight: bold;
				margin-bottom: 20rpx;
				
				text {
					font-size: 24rpx;
					font-weight: normal;
				}
			}
		}
		
		
	}
</style>
